package com.ruoyi.logistic.controller;

import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.domain.vo.TableVo;
import com.ruoyi.common.service.TableService;
import com.ruoyi.logistic.domain.*;
import com.ruoyi.logistic.domain.vo.NetworkHqPrePaymentVo;
import com.ruoyi.logistic.service.NetworkBusinessService;
import com.ruoyi.logistic.service.NetworkHqPrePaymentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/network/handworkBill")
@RestController
@Api(tags = "网点财务_总部预付款")
public class NetworkHqPrePaymentController {
    @Autowired
    private NetworkBusinessService networkBusinessService;
    @Autowired
    private NetworkHqPrePaymentService networkHqPrePaymentService;
    @Autowired
    private TableService tableService;

    @ApiOperation("显示业务类型下拉列表")
    @GetMapping("/selectBusinessAll")
    public R selectBusinessAll(){
        List<NetworkBusiness> businessList = networkBusinessService.selectAll();
        if (businessList == null || businessList.size() == 0){
            return R.fail("暂无数据");
        }else {
            return R.ok(businessList);
        }
    }

    @ApiOperation("显示费用科目下拉列表")
    @GetMapping("/selectFeeNameAll")
    public R selectFeeNameAll(){
        List<NetworkHqPreFeeName> list = networkHqPrePaymentService.selectAll();
        if (list == null || list.size() == 0){
            return R.fail("暂无数据");
        }else {
            return R.ok(list);
        }
    }

//    @ApiOperation("显示总部预付款流水列表")
//    @GetMapping("/selectAll")
//    public R selectAll(PageDate pageDate){
//        List<NetworkHqPrePayment> hqPrePaymentList = networkHqPrePaymentService.selectAll(pageDate);
//        if (hqPrePaymentList == null || hqPrePaymentList.size() == 0){
//            return R.fail("暂无数据");
//        }else {
//            return R.ok(PageInfo.info(hqPrePaymentList));
//        }
//    }
//    @ApiOperation("添加总部预付款流水")
//    @PostMapping("/insert")
//    public R insert(@RequestBody NetworkHqPrePayment networkHqPrePayment){
//        Boolean isAdd = networkHqPrePaymentService.insert(networkHqPrePayment);
//        if (isAdd){
//            return R.ok("添加成功");
//        }else {
//            return R.fail("添加失败");
//        }
//    }
//    @ApiOperation("修改总部预付款流水")
//    @PostMapping("/update")
//    public R update(@RequestBody NetworkHqPrePayment networkHqPrePayment){
//        Boolean isUpdate = networkHqPrePaymentService.update(networkHqPrePayment);
//        if (isUpdate){
//            return R.ok("修改成功");
//        }else {
//            return R.fail("修改失败");
//        }
//    }
//    @ApiOperation("删除总部预付款流水")
//    @PostMapping("/deleteById")
//    public R deleteById(Integer id){
//        Boolean isDelete = networkHqPrePaymentService.deleteById(id);
//        if (isDelete){
//            return R.ok("删除成功");
//        }else {
//            return R.fail("删除失败");
//        }
//    }
    @ApiOperation("搜索总部预付款流水")
    @PostMapping("/search")
    public R search(@RequestBody NetworkHqPrePaymentVo networkHqPrePaymentVo){
        List<NetworkHqPrePayment> hqPrePaymentList = networkHqPrePaymentService.search(networkHqPrePaymentVo);
        if (hqPrePaymentList == null || hqPrePaymentList.size() == 0){
            return R.fail("暂无数据");
        }else {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("list", PageInfo.info(hqPrePaymentList));
            jsonObject.put("fields", networkHqPrePaymentService.initTable());
            return R.ok(jsonObject);
        }
    }

    @ApiOperation("我的账户")
    @GetMapping("/myAccount")
    public R myAccount(String networkNameId){
        List<NetworkHqPreMyAccount> myAccounts = networkHqPrePaymentService.myAccount(networkNameId);
        List<TableVo> fieldList = tableService.getFieldAnnotation(new NetworkHqPreMyAccount());
        com.alibaba.fastjson.JSONObject jsonObject = new com.alibaba.fastjson.JSONObject();
        jsonObject.put("list", myAccounts);
        jsonObject.put("fields", fieldList);
        if (myAccounts == null || myAccounts.size() == 0) {
            return R.ok("暂无数据");
        } else {
            return R.ok(jsonObject);
        }
    }


}
